//
//  ProjectManagementSonViewController.m
//  Againstpoor
//
//  Created by 辰领科技 on 16/11/8.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ProjectManagementSonViewController.h"
#import "ProjectManagementSonTableViewCell.h"
#import "LeftTableViewCell.h"
#import "RightTableViewCell.h"
#import "ProgressTableViewCell.h"
#import "ProjectDetailsViewController.h"
#import "DetailsViewController.h"

static NSString * tableviewIndentifer = @"tableviewCell";

@interface ProjectManagementSonViewController ()
<UITableViewDelegate,UITableViewDataSource> {
    NSInteger _totle;
    
    NSString *idType;//项目列表
    NSString *address;//地址
    NSString *kind;//项目性质
    NSString *pressType;//进展情况
    
    NSString *plant;//规划投资
    NSString *actual;//实际投资
}
@property (nonatomic,assign)   NSInteger    pageNO;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIView *buttonView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UITableView *leftTableView;
@property (weak, nonatomic) IBOutlet UITableView *rightTableView;
@property (weak, nonatomic) IBOutlet UITableView *ProgressTableView;
@property (weak, nonatomic) IBOutlet UIButton *BGbutton;

@property (weak, nonatomic) IBOutlet UIButton *imageButtonOne;
@property (weak, nonatomic) IBOutlet UIButton *imageButtonTwo;
@property (weak, nonatomic) IBOutlet UIButton *imageButtonThree;
@property (weak, nonatomic) IBOutlet UIButton *imageButtonFour;
@property (weak, nonatomic) IBOutlet UIButton *buttonOne;
@property (weak, nonatomic) IBOutlet UIButton *buttonTwo;
@property (weak, nonatomic) IBOutlet UIButton *buttonThree;
@property (weak, nonatomic) IBOutlet UIButton *buttonFour;

@property (assign, nonatomic) NSInteger leftCount;
@property (assign, nonatomic) NSInteger rightCount;
@property (assign, nonatomic) NSInteger ProgressCount;

@property (strong, nonatomic) NSMutableArray *leftArray;
@property (strong, nonatomic) NSMutableArray *rightArray;
@property (strong, nonatomic) NSMutableArray *array;

@end

@implementation ProjectManagementSonViewController


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (_type == 1) {
        _titleLabel.text = @"扶贫项目管理";
        [_buttonTwo setTitle:@"扶贫地址" forState:UIControlStateNormal];
        [_buttonThree setTitle:@"项目性质" forState:UIControlStateNormal];
    } else if (_type == 2) {
        _titleLabel.text = @"扶贫资金管理";
        [_buttonTwo setTitle:@"规划投资" forState:UIControlStateNormal];
        [_buttonThree setTitle:@"实际投资" forState:UIControlStateNormal];
    }
    [self.tableView.header beginRefreshing];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _pageNO = 1;
    idType = @"";
    address = @"";
    kind = @"";
    pressType = @"";
    plant = @"";
    actual = @"";
    _leftArray = [NSMutableArray array];
    _rightArray = [NSMutableArray array];
    _array = [NSMutableArray array];
    _leftCount = 0;
    _rightCount = 100;
    _ProgressCount = 0;
    [self initViewLayout];
    [self addRefreshing];
}
- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.buttonView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    self.leftTableView.backgroundColor = kGetColor(244, 244, 244);
    
    self.rightTableView.delegate = self;
    self.rightTableView.dataSource = self;
    
    self.ProgressTableView.delegate = self;
    self.ProgressTableView.dataSource = self;
    
    _BGbutton.alpha = 0;
}

#pragma mark -- 添加刷新数据
- (void)addRefreshing{
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        int64_t delayInSeconds = 8.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [self.tableView.header endRefreshing];
        });
        self.pageNO = 1;
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            if (_type == 1) {
                [self getProjectList];
            } else if (_type == 2) {
                [self getmoneyList];
            }
        });
    }];
    [_tableView.header beginRefreshing];
}
//加载更多数据
- (void)loadMoreData{
    if (self.array.count == _totle) {
        [self.tableView.footer endRefreshing];
    }else{
        self.pageNO = self.pageNO + 1;
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            if (_type == 1) {
                [self getProjectList];
            } else if (_type == 2) {
                [self getmoneyList];
            }
        });
    }
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 搜索
- (IBAction)search:(id)sender {
}

#pragma mark - 查询项目分类
- (void)getProjectClassification {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_projectType withHttpType:@"POST" withTag:F_F_projectType];
}

#pragma mark - 查询扶贫项目列表
- (void)getProjectList {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    self.shareApi.delegate = self;
    if (![idType isEqualToString:@""]) {
        [dic setObject:idType forKey:@"type"];
    }
    if (![address isEqualToString:@""]) {
        [dic setObject:address forKey:@"address"];
    }
    if (![kind isEqualToString:@""]) {
        [dic setObject:kind forKey:@"kind"];
    }
    if (![pressType isEqualToString:@""]) {
        [dic setObject:pressType forKey:@"pressType"];
    }
    if (_typeTwo == 1) {
        [dic setObject:_department forKey:@"department"];
    } else if (_typeTwo == 2) {
        [dic setObject:_areaCode forKey:@"areaCode"];
    } else if (_typeTwo == 3) {
        
    }
    [dic setObject:_implementTime forKey:@"implementTime"];
    [dic setObject:[NSString stringWithFormat:@"%d",_pageNO] forKey:@"pageNum"];
    [dic setObject:[NSString stringWithFormat:@"%d",PageSize] forKey:@"pageSize"];
    [self.shareApi  requestOperationWithDic:dic withPath:F_projectList withHttpType:@"POST" withTag:F_F_projectList];
}

#pragma mark - 扶贫资金管理条件查询项目列表
- (void)getmoneyList {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    self.shareApi.delegate = self;
    if (![idType isEqualToString:@""]) {
        [dic setObject:idType forKey:@"type"];
    }
    if (![plant isEqualToString:@""]) {
        [dic setObject:plant forKey:@"plant"];
    }
    if (![actual isEqualToString:@""]) {
        [dic setObject:actual forKey:@"actual"];
    }
    if (![pressType isEqualToString:@""]) {
        [dic setObject:pressType forKey:@"pressType"];
    }
    if (_typeTwo == 1) {
        [dic setObject:_department forKey:@"department"];
    } else if (_typeTwo == 2) {
        [dic setObject:_areaCode forKey:@"areaCode"];
    } else if (_typeTwo == 3) {
        
    }
    [dic setObject:_implementTime forKey:@"implementTime"];
    [dic setObject:[NSString stringWithFormat:@"%d",_pageNO] forKey:@"pageNum"];
    [dic setObject:[NSString stringWithFormat:@"%d",PageSize] forKey:@"pageSize"];
    [self.shareApi  requestOperationWithDic:dic withPath:F_priceProjectList withHttpType:@"POST" withTag:F_F_priceProjectList];
}

#pragma mark - 镇列表
- (void)getpoorAreaTown {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_poorAreaTown withHttpType:@"POST" withTag:F_F_poorAreaTown];
}

#pragma mark - 村列表
- (void)getpoorAreaCountry {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setObject:[Common stringFromData:_leftArray[_leftCount][@"code"]] forKey:@"code"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_poorAreaCountry withHttpType:@"POST" withTag:F_F_poorAreaCountry];
}

#pragma mark - 项目类别 && 扶贫地址 && 项目性质 && 进展情况
- (IBAction)button:(UIButton *)sender {
    
    if (sender == _buttonOne) {
        //项目类别
        [self getProjectClassification];
        
        _buttonOne.selected = YES;
        _buttonTwo.selected = NO;
        _buttonThree.selected = NO;
        _buttonFour.selected = NO;
        _imageButtonOne.selected = YES;
        _imageButtonTwo.selected = NO;
        _imageButtonThree.selected = NO;
        _imageButtonFour.selected = NO;

        
    } else if (sender == _buttonTwo) {
        //扶贫地址 && 规划投资
        
        _buttonOne.selected = NO;
        _buttonTwo.selected = YES;
        _buttonThree.selected = NO;
        _buttonFour.selected = NO;
        _imageButtonOne.selected = NO;
        _imageButtonTwo.selected = YES;
        _imageButtonThree.selected = NO;
        _imageButtonFour.selected = NO;
        
        [UIView animateWithDuration:0.5 animations:^{

            if (_type == 1) {
                [self getpoorAreaTown];
            } else if (_type == 2) {
                _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 0), NO);
                _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 0), NO);
                _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 45*2), NO);
            }
            _BGbutton.alpha = 0.5;
        }];
        [self.ProgressTableView reloadData];
    } else if (sender == _buttonThree) {
        //项目性质 && 实际投资
        _buttonOne.selected = NO;
        _buttonTwo.selected = NO;
        _buttonThree.selected = YES;
        _buttonFour.selected = NO;
        _imageButtonOne.selected = NO;
        _imageButtonTwo.selected = NO;
        _imageButtonThree.selected = YES;
        _imageButtonFour.selected = NO;

        
        [UIView animateWithDuration:0.5 animations:^{
            _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 0), NO);
            _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 0), NO);
            if (_type == 1) {
                _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 45*4), NO);
            } else if (_type == 2) {
                _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 45*2), NO);
            }
            _BGbutton.alpha = 0.5;
        }];
        [self.ProgressTableView reloadData];
    } else if (sender == _buttonFour) {
        //进展情况
        _buttonOne.selected = NO;
        _buttonTwo.selected = NO;
        _buttonThree.selected = NO;
        _buttonFour.selected = YES;
        _imageButtonOne.selected = NO;
        _imageButtonTwo.selected = NO;
        _imageButtonThree.selected = NO;
        _imageButtonFour.selected = YES;

        [UIView animateWithDuration:0.5 animations:^{
            _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 0), NO);
            _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 0), NO);
            _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 45*4), NO);
            _BGbutton.alpha = 0.5f;
        }];
        [self.ProgressTableView reloadData];
    }
}
- (IBAction)hidden:(id)sender {
    [UIView animateWithDuration:0.5 animations:^{
        _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 0), NO);
        _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 0), NO);
        _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
        _BGbutton.alpha = 0;
    }];
}


#pragma mark - <UITableViewDelegate&&UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

//定义 UITableView cell 的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.tableView) {
        return _array.count;
    } else if (tableView == _leftTableView) {
        return _leftArray.count;
    } else if (tableView == _rightTableView) {
        return _rightArray.count;
    } else {
        if (_type == 1) {
            return 4;
        } else if (_type == 2) {
            if (_buttonThree.selected || _buttonFour.selected) {
                return 4;
            } else {
                return 2;
            }
        }
        return 0;
    }
    
}

//定义 UITableView cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.tableView) {
        return 80*VerticalRatio();
    } else {
        return 45*VerticalRatio();
    }
    
}

//定义 UITableView cell 展示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.tableView) {
        ProjectManagementSonTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:tableviewIndentifer];
        if (cell == nil) {
            cell= [[ProjectManagementSonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableviewIndentifer];
        }
        NSDictionary *dic = _array[indexPath.row];
        if (_type == 1) {
            cell.numberLabel.hidden = YES;
            cell.titleLabel.text = [Common stringFromData:dic[@"name"]];
            NSString *_kind = [Common stringFromData:dic[@"kind"]];
            if ([_kind isEqualToString:@"01"]) {
                cell.labelOne.text = @"项目性质：新建";
            } else if ([_kind isEqualToString:@"02"]) {
                cell.labelOne.text = @"项目性质：改建";
            } else if ([_kind isEqualToString:@"03"]) {
                cell.labelOne.text = @"项目性质：整修";
            } else if ([_kind isEqualToString:@"04"]) {
                cell.labelOne.text = @"项目性质：硬化";
            }
            cell.labelTwo.text = [NSString stringWithFormat:@"扶贫地址：%@%@",[Common stringFromData:dic[@"town"]],[Common stringFromData:dic[@"country"]]];
            cell.labelThree.text = [NSString stringWithFormat:@"实施年限：%@",[Common stringFromData:dic[@"time"]]];
            NSString *_pressType = [Common stringFromData:dic[@"pressType"]];
            if ([_pressType isEqualToString:@"01"]) {
                cell.labelFour.text = @"进展情况：未开工";
            } else if ([_pressType isEqualToString:@"02"]) {
                cell.labelFour.text = @"进展情况：开工在建";
            } else if ([_pressType isEqualToString:@"03"]) {
                cell.labelFour.text = @"进展情况：已完成";
            } else if ([_pressType isEqualToString:@"04"]) {
                cell.labelFour.text = @"进展情况：已验收";
            }
        } else if (_type == 2) {
            cell.labelOne.hidden = YES;
            cell.labelTwo.hidden = YES;
            
            cell.titleLabel.text = [Common stringFromData:dic[@"name"]];
            cell.numberLabel.text = [NSString stringWithFormat:@"石柱特产发[%@]",[Common stringFromData:dic[@"plantNum"]]];
            
            NSString * one = [NSString stringWithFormat:@"%@",[Common stringFromData:dic[@"totalInvestment"]]];
            NSMutableAttributedString * strOne = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"总投资：￥%@万",one]];
            [strOne addAttribute:NSForegroundColorAttributeName value:kGetColor(182, 2, 1) range:NSMakeRange(4, one.length+2)];
            [cell.labelThree setAttributedText:strOne];
            NSString * two = [NSString stringWithFormat:@"%@",[Common stringFromData:dic[@"specialPrice"]]];
            NSMutableAttributedString * strtwo = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"扶贫资金：￥%@万",two]];
            [strtwo addAttribute:NSForegroundColorAttributeName value:kGetColor(182, 2, 1) range:NSMakeRange(5, two.length+2)];
            [cell.labelFour setAttributedText:strtwo];
        }
        
        return cell;
    } else if (tableView == _leftTableView) {
        LeftTableViewCell *cell = [self.leftTableView dequeueReusableCellWithIdentifier:tableviewIndentifer];
        if (cell == nil) {
            cell= [[LeftTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableviewIndentifer];
        }
        
        if (_buttonOne.selected) {
            cell.label.text = [Common stringFromData:_leftArray[indexPath.row][@"name"]];
        } else if (_buttonTwo.selected) {
            NSDictionary *dic = _leftArray[indexPath.row];
            cell.label.text = [Common stringFromData:dic[@"address"]];
        }
        
        cell.backgroundColor = kGetColor(244, 244, 244);
        if (indexPath.row == _leftCount) {
            cell.backgroundColor = kGetColor(255, 255, 255);
        }
        
        return cell;
    } else if (tableView == _rightTableView) {
        RightTableViewCell *cell = [self.rightTableView dequeueReusableCellWithIdentifier:tableviewIndentifer];
        if (cell == nil) {
            cell= [[RightTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableviewIndentifer];
        }
        
        if (_buttonOne.selected) {
            cell.label.text = [Common stringFromData:_rightArray[indexPath.row][@"name"]];
        } else if (_buttonTwo.selected) {
            NSDictionary *dic = _rightArray[indexPath.row];
            cell.label.text = [Common stringFromData:dic[@"address"]];
        }
        
        cell.label.textColor = kGetColor(62, 62, 62);
        cell.button.selected = NO;
        if (indexPath.row == _rightCount) {
            cell.label.textColor = kGetColor(0, 82, 164);
            cell.button.selected = YES;
        }
        
        return cell;
    } else {
        ProgressTableViewCell *cell = [self.ProgressTableView dequeueReusableCellWithIdentifier:tableviewIndentifer];
        if (cell == nil) {
            cell= [[ProgressTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableviewIndentifer];
        }
        
        if (_buttonThree.selected) {
            if (_type == 1) {
                cell.label.text = [NSString stringWithFormat:@"%@",self.conditionsArray[indexPath.row]];
            } else if (_type == 2) {
                cell.label.text = [NSString stringWithFormat:@"%@",self.planningArray[indexPath.row]];
            }
        } else if (_buttonFour.selected) {
            cell.label.text = [NSString stringWithFormat:@"%@",self.progressArray[indexPath.row]];
        } else if (_buttonTwo.selected) {
            if (_type == 2) {
                cell.label.text = [NSString stringWithFormat:@"%@",self.planningArray[indexPath.row]];
            }
            
        }
        
        cell.label.textColor = kGetColor(62, 62, 62);
        cell.button.selected = NO;
        if (indexPath.row == _ProgressCount) {
            cell.label.textColor = kGetColor(0, 82, 164);
            cell.button.selected = YES;
        }
        
        return cell;
    }
    
    
//    for (UIView *view in cell.subviews) {
//        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
//            [view removeFromSuperview];
//        }
//    }
}

//定义 UITableView cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [_tableView.footer endRefreshing];
    [_tableView.header endRefreshing];
    if (tableView == _tableView) {
        if (_type == 1) {
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomePageStoryboard" bundle:nil];
            ProjectDetailsViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ProjectDetails"];
            page.ID = [Common stringFromData:_array[indexPath.row][@"id"]];
            page.titleStr = [Common stringFromData:_array[indexPath.row][@"name"]];
            [[Common getNavigation]pushViewController:page];
        } else if (_type == 2) {
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomePageStoryboard" bundle:nil];
            DetailsViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Details"];
            page.ID = [Common stringFromData:_array[indexPath.row][@"id"]];
            page.titleStr = [Common stringFromData:_array[indexPath.row][@"name"]];
            [[Common getNavigation]pushViewController:page];
        }
    } else if (tableView == _leftTableView) {
        _leftCount = indexPath.row;
        
        if (_buttonOne.selected) {
            _rightArray = _leftArray[_leftCount][@"projectList"];
            CGFloat lefthight = 45*_leftArray.count;
            if (lefthight > 448) {
                lefthight = 448;
            }
            CGFloat righthight = 45*_rightArray.count;
            if (righthight > 448) {
                righthight = 448;
            }
            [UIView animateWithDuration:0.5 animations:^{
                _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, lefthight), NO);
                _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, righthight), NO);
                _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
                _BGbutton.alpha = 0.5;
            }];
        } else if (_buttonTwo.selected) {
            CGFloat lefthight = 45*_leftArray.count;
            if (lefthight > 448) {
                lefthight = 448;
            }
            [UIView animateWithDuration:0.5 animations:^{
                if (_type == 1) {
                    _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, lefthight), NO);
                    _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 45*10), NO);
                    _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
                } else if (_type == 2) {
                }
                _BGbutton.alpha = 0.5;
            }];
            [self getpoorAreaCountry];
        }
        [self.leftTableView reloadData];
        [self.rightTableView reloadData];
    } else if (tableView == _rightTableView) {
//        _rightCount = indexPath.row;
//        [self.leftTableView reloadData];
//        [self.rightTableView reloadData];
        [UIView animateWithDuration:0.5 animations:^{
            _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 0), NO);
            _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 0), NO);
            _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
            _BGbutton.alpha = 0;
        }];
        
        if (_type == 1) {
            if (_buttonOne.selected) {
                idType = [Common stringFromData:_rightArray[indexPath.row][@"id"]];
            } else if (_buttonTwo.selected) {
                address = [Common stringFromData:_rightArray[indexPath.row][@"code"]];
            }
            
        }
        
    } else if (tableView == _ProgressTableView) {
        _ProgressCount = indexPath.row;
        [self.ProgressTableView reloadData];
        [UIView animateWithDuration:0.5 animations:^{
            _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 0), NO);
            _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 0), NO);
            _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
            _BGbutton.alpha = 0;
        }];
        
        if (_type == 1) {
            if (_buttonThree.selected) {
                if (indexPath.row == 0) {
                    kind = @"01";
                } else if (indexPath.row == 1) {
                    kind = @"02";
                } else if (indexPath.row == 2) {
                    kind = @"03";
                } else if (indexPath.row == 3) {
                    kind = @"04";
                }
            } else if (_buttonFour.selected) {
                if (indexPath.row == 0) {
                    pressType = @"01";
                } else if (indexPath.row == 1) {
                    pressType = @"02";
                } else if (indexPath.row == 2) {
                    pressType = @"03";
                } else if (indexPath.row == 3) {
                    pressType = @"04";
                }
            }
        } else if (_type == 2) {
            if (_buttonTwo.selected) {
                if (indexPath.row == 0) {
                    plant = @"01";
                } else if (indexPath.row == 1) {
                    plant = @"02";
                }
                actual = @"";
            } else if (_buttonThree.selected) {
                if (indexPath.row == 0) {
                    actual = @"01";
                } else if (indexPath.row == 1) {
                    actual = @"02";
                }
                plant = @"";
            }

        }
    }
    [self.tableView.header beginRefreshing];
}

#pragma mark - Custom Accessor
- (NSArray *)conditionsArray {
    NSArray *conditionsArray;
    if (!conditionsArray) {
        conditionsArray = @[@"新建",@"改建",@"整修",@"硬化"];
    }
    return conditionsArray;
}
- (NSArray *)progressArray {
    NSArray *progressArray;
    if (!progressArray) {
        progressArray = @[@"未开工",@"开工在建",@"已完成",@"已验收"];
    }
    return progressArray;
}
- (NSArray *)planningArray {
    NSArray *planningArray;
    if (!planningArray) {
        planningArray = @[@"升序",@"降序"];
    }
    return planningArray;
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    [_tableView.footer endRefreshing];
    [_tableView.header endRefreshing];
    if (tag==F_F_projectType) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            _leftArray = database[@"data"];
            _rightArray = _leftArray[0][@"projectList"];
            if (_buttonOne.selected) {
                [UIView animateWithDuration:0.5 animations:^{
                    _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, 45*_leftArray.count), NO);
                    _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, 45*_rightArray.count), NO);
                    _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
                    _BGbutton.alpha = 0.5;
                }];
            }
            [self.leftTableView reloadData];
            [self.rightTableView reloadData];
        }else  {
        }
    } else if (tag==F_F_projectList || tag==F_F_priceProjectList) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                _totle = [database[@"total"] integerValue];
                if (_totle > PageSize) {
                    __weak __typeof(self) weakSelf = self;
                    if (!self.tableView.footer) {
                        // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
                        self.tableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                            [weakSelf loadMoreData];
                        }];
                    }
                }
                if (self.pageNO == 1) {
                    [self.array removeAllObjects];
                }
                
                NSArray *arr = database[@"rows"];
                for (id entity in arr) {
                    [self.array addObject:entity];
                }
                [_tableView reloadData];
            });
        }else  {
        }
    } else if (tag==F_F_poorAreaTown) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            _leftArray = database[@"data"];
            [_leftTableView reloadData];
            [self getpoorAreaCountry];
        }else  {
            
        }
    } else if (tag==F_F_poorAreaCountry) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            _rightArray = database[@"data"];
            CGFloat lefthight = 45*_leftArray.count;
            if (lefthight > 448) {
                lefthight = 448;
            }
            CGFloat righthight = 45*_rightArray.count;
            if (righthight > 448) {
                righthight = 448;
            }
            [UIView animateWithDuration:0.5 animations:^{
                _leftTableView.frame = flexibleFrame(CGRectMake(0, 120, 120, lefthight), NO);
                _rightTableView.frame = flexibleFrame(CGRectMake(120, 120, 200, righthight), NO);
                _ProgressTableView.frame = flexibleFrame(CGRectMake(0, 120, 320, 0), NO);
                _BGbutton.alpha = 0.5;
            }];
            [_rightTableView reloadData];
        }else  {
            
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [_tableView.footer endRefreshing];
    [_tableView.header endRefreshing];
    [self dismissWaitDialog];
    
}
@end
